package com.ujiuye.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ujiuye.config.PageResult;
import com.ujiuye.config.QueryPageBean;
import com.ujiuye.mapper.PermissionMapper;
import com.ujiuye.pojo.Permission;
import com.ujiuye.service.IPermissionService;
import org.apache.dubbo.config.annotation.Service;


import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 权限 服务实现类
 * </p>
 *
 * @author zs
 * @since 2021-07-05
 */
@Service
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements IPermissionService {
    @Resource
    private PermissionMapper permissionMapper;
    @Override
    public PageResult list(QueryPageBean queryPageBean) {
        Page<Permission> page = new Page<>(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        String queryString = queryPageBean.getQueryString();
        QueryWrapper<Permission> queryWrapper = new QueryWrapper<>();
        if (queryString!=null && queryString.length()>0){
            queryWrapper.eq("name",queryString).or().eq("keyword",queryString);
        }
        Page<Permission> permissionPage = permissionMapper.selectPage(page, queryWrapper);
        PageResult pageResult = new PageResult(permissionPage.getTotal(),permissionPage.getRecords());
        return pageResult;
    }

    @Override
    public List<Permission> getPermissionById(int id) {
        return  permissionMapper.getPermissionById(id);
    }
}
